import swaggerJSDoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';

// import { version } from '../../../package.json';

const options = {
    definition: {
        openapi: '3.0.0',
        info: {
            title: 'API DOCS',
            version: '1.0.0',
        },
        components: {
            securitySchemes: {
                bearerAuth: {
                    type: 'http',
                    scheme: 'bearer',
                    bearerFormat: 'JWT',
                },
            },
        },
        security: [{ bearerAuth: [] }],
    },
    apis: ['./src/index.js', './src/schemas/*.js'],
};

const swaggerDoc = swaggerJSDoc(options);

export const swagger = (app, port) => {
    app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerDoc));

    app.get('/api/v1/version', (req, res) => {
        res.setHead({ 'Content-Type': 'application/json' });
        res.send({ swaggerDoc });
    });
};
